package com.example.demo.common;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author zhouzq1@chinaexpressair.com
 * @title
 * @date 2021/10/27 9:45
 **/
@Getter
@Setter
public class ResponseDTO<T> {

    private String code;

    private String message;

    private T data;


    public static <T> ResponseDTO<T> success(T data, String msg) {
        ResponseDTO<T> responseDto = new ResponseDTO<>();
        responseDto.setCode(APIStateEnum.SUCCESS.getCode());
        responseDto.setData(data);
        responseDto.setMessage(StringUtils.isNotEmpty(msg) ? msg : APIStateEnum.SUCCESS.getMsg());
        return responseDto;
    }


    public static <T> ResponseDTO<T> fail(T data, String msg) {
        ResponseDTO<T> responseDto = new ResponseDTO<>();
        responseDto.setCode(APIStateEnum.FAILED.getCode());
        responseDto.setData(data);
        responseDto.setMessage(StringUtils.isNotEmpty(msg) ? msg : APIStateEnum.FAILED.getMsg());
        return responseDto;
    }

}
